package com.mingdinggroup.app.util;

import android.media.MediaPlayer;


/**
 * 作者：woodnaonly on 2017/3/14 11:30
 * 邮箱：497917264@qq.com
 * 内容：
 * 备注：
 */
public class MediaPlayerUtils {

    private static MediaPlayerUtils MediaPlayerUtilsInstance = null;
    private static MediaPlayer mMediaPlayer;

    public static MediaPlayerUtils getSingleton() {
        if (MediaPlayerUtilsInstance == null) {
            synchronized (MediaPlayerUtils.class) {
                if (MediaPlayerUtilsInstance == null) {
                    MediaPlayerUtilsInstance = new MediaPlayerUtils();
                }
            }
        }
        return MediaPlayerUtilsInstance;
    }

    //	public static MediaPlayer getInstance() {
    //		Holder.mediaPlayer.release();
    //		return Holder.mediaPlayer;
    //	}
    //
    private MediaPlayerUtils() {
        mMediaPlayer = new MediaPlayer();
    }
    //
    //	private static class Holder {
    //		public static final MediaPlayer mediaPlayer = new MediaPlayer();
    //	}

    public synchronized void play(String path) {
        MediaPlayer mediaPlayer = mMediaPlayer;
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
            mediaPlayer.reset();
            mediaPlayer = null;
            //			mMediaPlayer=new MediaPlayer();
        }
        mMediaPlayer = new MediaPlayer();
        mediaPlayer = mMediaPlayer;
        try {
            mediaPlayer.setDataSource(path);
            mediaPlayer.prepare();
            mediaPlayer.start();
        } catch (Exception e) {
            e.printStackTrace();

        }
        //		mMediaPlayer.stop();
        //		try {
        //			mMediaPlayer.setDataSource(path);
        //			mMediaPlayer.prepare();
        //			mMediaPlayer.start();
        //		} catch (Exception e) {
        //			e.printStackTrace();
        //			KLog.d(e.getLocalizedMessage());
        //		}

        //		MediaPlayer mediaPlayer =new MediaPlayer();
        ////		mediaPlayer.release();
        ////		mediaPlayer = getInstance();
        //		try {
        //			mediaPlayer.setDataSource("/storage/emulated/0/com.mingdinggroup.app1/nim/2caaa009-0388-483c-a36b-b151708231af.aac");
        //			mediaPlayer.prepare();
        //			mediaPlayer.start();
        //		} catch (Exception e) {
        //			e.printStackTrace();
        //			KLog.d(e.getLocalizedMessage()
        //			);
        //		}

    }
}
